package stone.ast;

import java.util.List;
import java.util.ArrayList;

import stone.Symbols;
import ASTInterpreter.Environment;

public class ClassBody extends ASTList {

	public ClassBody(List<ASTree> list) {
		super(list);
	}
	
	/*
	public Object eval(Environment env) {
		for (ASTree t : this) {
			t.eval(env);
		}
		return null;
	}
	*/

	public Object eval(Environment env) {
		// 不对def语句进行evaluate
		for (ASTree t : this) {
			if (!(t instanceof DefStmnt)) {
				t.eval(env);
			}
		}
		return null;
	}

	public void lookup(Symbols symbols, Symbols methodNames,
		Symbols fieldNames, ArrayList<DefStmnt> methods) {
		for (ASTree t : this) {
			if (t instanceof DefStmnt) {
				DefStmnt def = (DefStmnt)t;
				int oldSize = methodNames.size();
				int i = methodNames.putNew(def.name());
				if (i >= oldSize) {
					methods.add(def);
				}
				else {
					methods.set(i, def);
				}
				def.lookupAsMethod(fieldNames);
			}
			else {
				t.lookup(symbols);
			}
		}
	}

}
